package com.zhongwang.mms.module.buy.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.module.buy.model.ShoppingPlanModel;
import com.zhongwang.mms.module.buy.service.EditBuyProgressService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Description: 采购管理 -> 采购进度编辑
 * 查看 -> buy:buyprogress:view
 * 编辑 -> buy:buyprogress:edit
 * @Author: China.sgl
 * @Date: 2020/4/7 14:42
 */
@SuppressWarnings("ALL")
@Controller
@RequestMapping("/buy/editBuyProgress")
public class EditBuyProgressController extends BaseController {

    @Autowired
    private EditBuyProgressService service;

    /**
     * 编辑采购计划进度页面
     *
     * @return 路径
     */
    @GetMapping
    @RequiresPermissions({"buy:buyprogress:view"})
    public String page() {
        return "buy/editBuyProgress/page";
    }


    /**
     * 采购计划列表数据
     *
     * @param shoppingPlanModel 查询条件
     * @return list
     */
    @ResponseBody
    @PostMapping("/list")
    @RequiresPermissions({"buy:buyprogress:view"})
    public JsonResult list(ShoppingPlanModel shoppingPlanModel) {
        startPage();
        List<ShoppingPlanModel> list = service.findBuyPlanByQuery(shoppingPlanModel);
        return jsonResult(list);
    }

    /**
     * 修改采购计划进度
     *
     * @param reportPlan reportPlan
     * @return json
     */
    @ResponseBody
    @PostMapping("/edit")
    @RequiresPermissions({"buy:buyprogress:edit"})
    public JsonResult edit(ShoppingPlanModel shoppingPlanModel) {
        return jsonResult(service.editPlanProgress(shoppingPlanModel));
    }

    /**
     * 导出采购进度
     *
     * @param ShoppingPlanModel param
     * @return json
     */
    @ResponseBody
    @GetMapping("/export")
    @RequiresPermissions({"buy:buyprogress:edit"})
    public void export(HttpServletResponse response, ShoppingPlanModel param) {
        service.export(response, param);
    }

    /**
     * 导入采购进度修改行号
     *
     * @param ShoppingPlanModel param
     * @return json
     */
    @ResponseBody
    @PostMapping("/import")
    @RequiresPermissions({"buy:buyprogress:edit"})
    public JsonResult importExcel(@RequestParam("file") MultipartFile file) {
        return service.importExcel(file);
    }

}
